package com.qumitech.visualnovel.service.gaming.impl;

import com.alibaba.fastjson.JSONObject;
import com.qumitech.visualnovel.component.util.HttpInvokeUtil;
import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.UrlConstant;
import com.qumitech.visualnovel.service.gaming.GamingService;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class GamingServiceImpl implements GamingService {
    private static final String PUBLICPOOL_URL = "/admin/gaming/%s/publicpool";

    @Override
    public BaseRsp getPublicPool(String gamingType) {
        String url = UrlConstant.SERVER_URL + String.format(PUBLICPOOL_URL, gamingType);
        JSONObject o = new JSONObject();
        Map<String, Object> req = JSONObject.toJavaObject(o, Map.class);
        String body = HttpInvokeUtil.httpGet(url, req);
        return JSONObject.parseObject(body, BaseRsp.class);
    }

    @Override
    public BaseRsp replacePublicPool(String gamingType, double publicPool) {
        String url = UrlConstant.SERVER_URL + String.format(PUBLICPOOL_URL, gamingType) + "/" + publicPool;
        String body = HttpInvokeUtil.httpPutJson(url, new JSONObject(), UrlConstant.DefaultEncode, null);
        return JSONObject.parseObject(body, BaseRsp.class);
    }
}
